<template>
  <div class="p-2">
    <slot name="title"></slot>
    <div
      v-for="item of selectList"
      :class="item.sessionId === fileSelectData?.sessionId ? 'bg-FileNavActive text-sky-400' : ''"
      class="p-2 rounded cursor-pointer hover:bg-FileHover"
      @click="SelectItem(item)"
    >
      <div class="flex flex-row gap-2 items-center">
        <n-avatar :src="item.avatar"></n-avatar>
        <p>{{ item.name }}</p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { IFriendListItem } from "@/types/friend";
import { IGroupListItem } from "@/types/group";
import { NAvatar } from "naive-ui";
import { IFileSelectData } from "@/types/file.ts";

type ISelectListProps = IGroupListItem | IFriendListItem;
const fileSelectData = defineModel<IFileSelectData>("fileSelectData");
withDefaults(
  defineProps<{
    selectList: ISelectListProps[];
  }>(),
  {
    selectList: () => [] as ISelectListProps[],
  },
);

function SelectItem(item: ISelectListProps) {
  fileSelectData.value = {
    id: item.id,
    sessionId: item.sessionId,
  };
}
</script>

<style lang="scss" scoped></style>
